package com.ruoyi.web.controller;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.QuerySection;
import com.ruoyi.common.core.domain.entity.Section;
import com.ruoyi.common.core.domain.entity.CommonDelete;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.ISectionService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author linxz
 * @since 2024-12-25
 */
@RestController
@RequestMapping("/section")
public class SectionController extends BaseController {


    @Autowired
    private ISectionService service;

    @PostMapping("/list")
    public TableDataInfo list(@RequestBody QuerySection query) {
        // 给sql语句添加limit查询
        PageHelper.startPage(query.getPageNum(), query.getPageSize());
        List<Section> sectionList = service.select(query.getDeviceType(),query.getLocate());
        return getDataTable(sectionList);

    }

    // 插入数据
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Section section) {
        // 手动设置状态 0 有效
        section.setStatus(0);
        if(service.add(section)>0){
            return AjaxResult.success();
        }else {
            return AjaxResult.error("模块名称不能重复");
        }
    }

    // 修改模块
    @PostMapping("/update")
    public AjaxResult update(@RequestBody Section section){
        return toAjax(service.update(section));
    }

    // 删除模块
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody CommonDelete commonDelete){
        return toAjax(service.delete(commonDelete));
    }





}
